home *** CD-ROM | disk | FTP | other *** search
/ Programmers Heaven 2 / Programmers Heaven 2.iso / files / graphics / library / wgt51_r2.zip / WGT5 / EXAMPLES / WGT12.C < prev    next >
Encoding:
C/C++ Source or Header  |  1996-08-03  |  3.6 KB  |  118 lines

  1. /*
  2. ==============================================================================
  3.               WordUp Graphics Toolkit Version 5.0                     
  4.                  Demonstration Program 12                         
  5.                                           
  6.  Demonstrates mouse functions and msetbounds.                                 
  7.                                           
  8.  *** PROJECT ***                                                             
  9.  This program requires the file WGT5_WC.LIB to be linked.                    
  10.                                           
  11.  *** DATA FILES ***                                                          
  12.  NONE                                                                        
  13.                                WATCOM C++ VERSION 
  14. ==============================================================================
  15. */
  16.  
  17. #include <wgt5.h>
  18.  
  19.  
  20. void main(void)
  21. {
  22.   short px,py,pbut;         /* Temporary variables for mouse information */
  23.   short ox,oy;
  24.   short oldmode;
  25.         
  26.   printf ("WGT Example #12\n\n");
  27.   printf ("This program will restrict mouse movements to a region in the center of the\n");
  28.   printf ("screen and allow the user to click and place filled circles within that\n");
  29.   printf ("area. Press a key to remove restrictions and draw lines anywhere on the\n");
  30.   printf ("screen. A third keypress ends the program.\n");
  31.   printf ("\n\nPress any key to continue.\n");
  32.   getch ();
  33.  
  34.   if ( !vgadetected () )
  35.   {
  36.     printf("Error - VGA card required for any WGT program.\n");
  37.     exit (0);
  38.   }
  39.   oldmode = wgetmode ();
  40.   vga256 ();
  41.  
  42.   wcls (0);
  43.   minit ();   /* Initialize mouse */
  44.   mon ();           /* turn it on */
  45.  
  46.   wtextcolor (15);
  47.   wtexttransparent (TEXTFGBG);
  48.  
  49.   msetbounds (50, 50, 270, 150);
  50.   /* Set new mouse boundaries */
  51.  
  52.   do {
  53.   /* Note that WGT 5.0 will automatically update the mouse
  54.      variables mouse.mx, mouse.my and mouse.but. It is recommended you store 
  55.      them in an alternate set of variables where you require to read in
  56.      the mouse position since the coordinates change continuously. */
  57.  
  58.     px = mouse.mx;
  59.     py = mouse.my;
  60.     pbut = mouse.but;  /* stores info into mouse.mx,mouse.my,mouse.but */
  61.  
  62.     wclip (0, 0, 319, 199); /* Reset clipping so text will show */
  63.     wgtprintf (0, 0, NULL, "X: %i     Y: %i     Button: %i      ", px, py, pbut);
  64.     wclip (50, 50, 270, 150);
  65.  
  66.     /* Clip circles to same area to give the effect of a small screen. */
  67.  
  68.     if (pbut != 0) /* button pressed */
  69.     {
  70.       moff ();                                 /* Remember to turn off the  */
  71.       wsetcolor (mouse.my);                    /* mouse cursors before drawing */
  72.       wfill_circle (mouse.mx, mouse.my, 30);   /* or the mouse shape will smear */
  73.       mon ();                                  /* on the screen. */
  74.     }
  75.   } while (!kbhit());
  76.   getch ();
  77.  
  78.   moff ();
  79.   wcls (0);
  80.   mon ();
  81.  
  82.   msetbounds (0, 0, 319, 199);              /* Set new mouse boundaries */
  83.   wclip (0, 0, 319, 199);                   /* Reset clipping */
  84.  
  85.   do {
  86.     px = mouse.mx;
  87.     py = mouse.my;
  88.     pbut = mouse.but;
  89.  
  90.     wgtprintf (0, 0, NULL, "X: %i     Y: %i     Button: %i      ", px, py, pbut);
  91.  
  92.     if (pbut != 0)      /* This will draw a continuous line while the
  93.                button is pressed. */
  94.     {
  95.       if (ox != -1)
  96.       {
  97.     moff ();
  98.     wsetcolor (mouse.my);
  99.     wline (ox, oy, px, py);
  100.     mon ();
  101.       }
  102.       ox = px;
  103.       oy = py;
  104.     }
  105.     else 
  106.     { 
  107.       ox = -1; 
  108.       oy = -1; 
  109.     }   /* Set to impossible values */
  110.  
  111.   } while (!kbhit ());
  112.   getch ();
  113.  
  114.   msetbounds (0, 0, 319, 199);
  115.   mdeinit ();                   /* Deinitialize the mouse handler */
  116.   wsetmode (oldmode);
  117. }
  118.